<?php
require_once("lib/util.php");
require_once("lib/db.php");
function make_user ($first_name, $last_name, $email, $password){
		$user_query= "INSERT INTO users (first_name, last_name, email, password) ".
		"VALUES (?, ?, ?, ?);";
		query ($user_query, array($first_name, $last_name, $email, $password));
}
		
		

//return true or false
function validate_user($post) {

	//make sure password is more than six chars
	if(strlen($post["pwd1"])<6){
		return false;
	}
	
	//make sure the two passwords match
	if($post["pwd1"]!=$post["pwd2"]){
		return false;
	}
	
	foreach($post as $value) {
		
		if(empty($value)){
			return false;
		}
	}
	
	return true;
}

if($_POST) {
	if(validate_user($_POST)) {
		//make a new user
		connect();
		print_r();
		make_user ($_POST["first_name"], $_POST["last_name"], $_POST["email"], $_POST["pwd1"]);
		print mysql_error();
		close ();
		redirect ("/nitpicker");
	} 
	else {
		////
		render("foo", array("name" => "eli"));
		////
	}
} else {
	render("new_user", array("failed" => false));
}


	

